<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>FileGetSize</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>FileGetSize</h1>

<p>Retrieves the size of a file.</p>

<pre class="Syntax">FileGetSize, OutputVar [, Filename, Units]</pre>
<h3>Parameters</h3>
<dl>

  <dt>OutputVar</dt>
  <dd><p>The name of the variable in which to store the retrieved size (rounded down to the nearest whole number).</p></dd>

  <dt>Filename</dt>
  <dd><p>The name of the target file, which is assumed to be in <a href="../Variables.htm#WorkingDir">%A_WorkingDir%</a> if an absolute path isn't specified. If omitted, the current file of the innermost enclosing <a href="LoopFile.htm">File-Loop</a> will be used instead.</p></dd>

  <dt>Units</dt>
  <dd><p>If present, this parameter causes the result to be returned in units other than bytes:<br>
      K = kilobytes<br>
      M = megabytes</p></dd>

</dl>

<h3>ErrorLevel</h3>
<p><span class="ver">[v1.1.04+]</span> This command is able to throw an exception on failure. For more information, see <a href="Catch.htm#RuntimeErrors">Runtime Errors</a>.</p>
<p><a href="../misc/ErrorLevel.htm">ErrorLevel</a> is set to 1 if there was a problem or 0 otherwise.</p>
<p><a href="../Variables.htm#LastError">A_LastError</a> is set to the result of the operating system's GetLastError() function.</p>

<h3>Remarks</h3>
<p>Files of any size are supported, even those over 4 gigabytes, and even if <em>Units</em> is bytes.</p>
<p>If the target file is a directory, the size will be reported as whatever the OS believes it to be (probably zero in all cases).</p>
<p>To calculate the size of folder, including all its files, follow this example:</p>
<pre>SetBatchLines, -1  <em>; Make the operation run at maximum speed.</em>
FolderSize = 0
FileSelectFolder, WhichFolder  <em>; Ask the user to pick a folder.</em>
Loop, %WhichFolder%\*.*, , 1
    FolderSize += %A_LoopFileSize%
MsgBox Size of %WhichFolder% is %FolderSize% bytes.</pre>
<h3>Related</h3>
<p><a href="FileGetAttrib.htm">FileGetAttrib</a>, <a href="FileSetAttrib.htm">FileSetAttrib</a>, <a href="FileGetTime.htm">FileGetTime</a>, <a href="FileSetTime.htm">FileSetTime</a>, <a href="FileGetVersion.htm">FileGetVersion</a>, <a href="LoopFile.htm">File-loop</a></p>
<h3>Example</h3>
<pre class="NoIndent">FileGetSize, OutputVar, C:\My Documents\test.doc  <em>; Retrieve the size in bytes.</em>
FileGetSize, OutputVar, C:\My Documents\test.doc, K  <em>; Retrieve the size in Kbytes.</em></pre>

</body>
</html>
